# coding: utf-8
import shutil,pytest,os
from multiprocessing import Pool

def run(device_info):

    pytest.main([ f"--cmdopt={device_info}",'%s'%device_info['test_case_path'] , "-vs", "--alluredir","target/allure-results"])

    os.system('allure generate ./target/allure-results -o ./target/allure-report --clean')

def start_run():

    try:
        shutil.rmtree("./target")  # 删除报告目录，删除后只能看到当前执行后的报告结果，不删除能看到执行的历史执行结果
    except:
        pass

    device_info1 = [
                {"devices_list":['0123456789ABCDEF'],"test_case_path":'./test_case','test_data_yaml':"group_data_1.yaml",'NO':"1"},
               {"devices_list":['Q5S5T19423012718'],"test_case_path":'./test_case','test_data_yaml':"group_data_2.yaml",'NO':"2"}

               ]#非交互用例



    device_info2 = [
                {"devices_list": ['0123456789ABCDEF', 'Q5S5T19423012718', ], "test_case_path": './test_case_jh', 'test_data_yaml': "group_data_1.yaml",'NO':"1"},
                #{"devices_list": ['0123456789ABCDEF', 'Q5S5T19423012718', ], "test_case_path": './test_case_jh','test_data_yaml': "group_data_2.yaml",'NO':"2"},
                ]#交互用例

    device_info_list=[device_info1,device_info2]

    for device_info in device_info_list:

        with Pool(len(device_info)) as pool:#len(device_info)拿到配置的设备数，实现多进程执行，
            pool.map(run, (device_info))
            pool.close()
            pool.join()


if __name__=="__main__":
    start_run()


